/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CompanyInfo;
/*     */ import com.newcrm.bean.Group;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.db.DealManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.util.Date;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ 
/*     */ public class ShowDashboardCustomerNum extends AbstractAction
/*     */ {
/*     */   public ShowDashboardCustomerNum(AbstractHttpServlet servlet)
/*     */   {
/*  35 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  42 */     response.setContentType("text/html;charset=utf-8");
/*  43 */     PrintWriter out = response.getWriter();
/*  44 */     JSONObject jsonObject = new JSONObject();
/*     */ 
/*  46 */     User user = super.getLoginUser(request);
/*  47 */     String userId = Util.getURLParameter(request.getParameter("userId"));
/*  48 */     String originalGroupId = Util.getURLParameter(request
/*  49 */       .getParameter("groupId"));
/*  50 */     int groupId = Util.getURLIntParameter(request.getParameter("groupId"));
/*     */ 
/*  53 */     if (((originalGroupId == null) || (originalGroupId.trim().length() == 0)) && (
/*  54 */       (userId == null) || (userId.trim().length() == 0))) {
/*  55 */       if ((!user.isAdmin) && (!user.isGroupAdmin())) {
/*  56 */         userId = user.userId;
/*     */       }
/*  59 */       else if (user.isAdmin) {
/*  60 */         groupId = -1;
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/*  65 */     int totalNum = 0;
/*  66 */     int totalContactedNum = 0;
/*  67 */     int contactedNum = 0;
/*  68 */     int notContactedNum = 0;
/*  69 */     int nextContactedNum = 0;
/*  70 */     int pendingDealNum = 0;
/*     */ 
/*  72 */     Date startDate = Util.str2Date(request.getParameter("start"));
/*  73 */     Date endDate = Util.str2Date(request.getParameter("end"));
/*     */ 
/*  75 */     DealManager dealManager = new DealManager();
/*  76 */     CustomerManager manager = new CustomerManager();
/*     */ 
/*  78 */     CompanyInfo company = super.getCompany(request);
/*     */ 
/*  80 */     if ((userId != null) && (userId.trim().length() > 0))
/*     */     {
/*  82 */       totalNum = manager.getTotalCustomerNumByUserId(user.companyId, 
/*  83 */         userId);
/*  84 */       totalContactedNum = manager.getTotalContactedCustomerNumByUserId(
/*  85 */         user.companyId, userId);
/*  86 */       contactedNum = manager.getContactedCustomerNumByUserId(
/*  87 */         user.companyId, userId, startDate, endDate);
/*  88 */       notContactedNum = manager.getNotContactedCustomerNumByUserId(
/*  89 */         user.companyId, userId);
/*  90 */       nextContactedNum = manager.getNextContactedCustomerNumByUserId(
/*  91 */         user.companyId, userId, startDate, endDate);
/*  92 */       pendingDealNum = dealManager.getPendingDealNumByUserId(
/*  93 */         user.companyId, userId);
/*     */     }
/*     */     else {
/*  96 */       String groupIds = "";
/*  97 */       if (groupId == 0) {
/*  98 */         groupIds = "0";
/*     */       } else {
/* 100 */         Group group = company.getGroupById(groupId);
/* 101 */         if (group != null)
/* 102 */           groupIds = group.getAllIds();
/*     */         else {
/* 104 */           groupIds = String.valueOf(user.groupId);
/*     */         }
/*     */       }
/*     */ 
/* 108 */       totalNum = manager.getTotalCustomerNumByGroupIds(user.companyId, 
/* 109 */         groupIds);
/* 110 */       totalContactedNum = manager.getTotalContactedCustomerNumByGroupIds(
/* 111 */         user.companyId, groupIds);
/* 112 */       contactedNum = manager.getContactedCustomerNumByGroupIds(
/* 113 */         user.companyId, groupIds, startDate, endDate);
/* 114 */       notContactedNum = manager.getNotContactedCustomerNumByGroupIds(
/* 115 */         user.companyId, groupIds);
/* 116 */       nextContactedNum = manager.getNextContactedCustomerNumByGroupIds(
/* 117 */         user.companyId, groupIds, startDate, endDate);
/* 118 */       pendingDealNum = dealManager.getPendingDealNumByGroupIds(
/* 119 */         user.companyId, groupIds);
/*     */     }
/*     */ 
/* 122 */     jsonObject.put("error", "0");
/* 123 */     jsonObject.put("totalNum", Integer.valueOf(totalNum));
/* 124 */     jsonObject.put("totalContactedNum", Integer.valueOf(totalContactedNum));
/* 125 */     jsonObject.put("contactedNum", Integer.valueOf(contactedNum));
/* 126 */     jsonObject.put("notContactedNum", Integer.valueOf(notContactedNum));
/* 127 */     jsonObject.put("nextContactedNum", Integer.valueOf(nextContactedNum));
/* 128 */     jsonObject.put("pendingDealNum", Integer.valueOf(pendingDealNum));
/* 129 */     out.println(jsonObject);
/* 130 */     out.flush();
/* 131 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ShowDashboardCustomerNum
 * JD-Core Version:    0.6.1
 */